home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / B_WZSEND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  12.9 KB  |  351 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*               The Opus Computer-Based Conversation System                */
  3. /*       (c) Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  4. /*                                                                          */
  5. /*                   YOOHOO is a trademark of Wynn Wagner III               */
  6. /*                                                                          */
  7. /*                            YOOHOO-YOOHOO/2U2 is                          */
  8. /*           Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*                    BinkleyTerm "SendWaZOO" Processor                     */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*  This module is a very simple FOSSIL-based terminal emulator. It is      */
  15. /*  provided for your information only.  You will find routines that need   */
  16. /*  to be coded and identifiers to be resolved. It has been previously      */
  17. /*  known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm"   */
  18. /*  does not preclude the possibility that another "OpusLink" or "OConnect" */
  19. /*  could be released.                                                      */
  20. /*                                                                          */
  21. /*  There is absolutely no guarantee that anything here will work.  If you  */
  22. /*  break this routine, you own both pieces.                                */
  23. /*                                                                          */
  24. /*  USAGE:  You may use this material in any program with no obligation     */
  25. /*          as long as there is no charge for your program.  For more       */
  26. /*          information about commercial use, contact the "OPUSinfo HERE"   */
  27. /*          BBS (124/111).                                                  */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31.  
  32. #include <signal.h>
  33. #include <ctype.h>
  34. #include <conio.h>
  35.  
  36. #define WAZOO_SECTION
  37. #include "zmodem.h"
  38.  
  39. #include "com.h"
  40. #define rb_plus "r+b"
  41.  
  42. extern char *BUNDLE_msg;
  43. extern char *FIND_msg;
  44. extern int n_requests;
  45. extern int caller;
  46. extern int sent_mail;
  47. extern int called_net, called_node;
  48.  
  49. extern int (*wzgetfunc)(), (*wzsendfunc)();
  50.  
  51. char *request_template = "%s%04x%04x.REQ";
  52.  
  53. char *ext_flags = "ODCH";                /* Change to whatever, and */
  54. #define NUM_FLAGS 4                /* bump this, to add flags */
  55.  
  56. int net_problems;                /* This should be external */
  57.  
  58. /*--------------------------------------------------------------------------*/
  59. /* SEND WaZOO (send another WaZOO-capable Opus its mail)                    */
  60. /*   returns TRUE (1) for good xfer, FALSE (0) for bad                      */
  61. /*   use instead of n_bundle and n_attach for WaZOO Opera                   */
  62. /*--------------------------------------------------------------------------*/
  63. int pascal send_WaZOO()
  64.    begin
  65.       FILE       *fp;
  66.       char        fname[80];
  67.       char        s[80];
  68.       char       *sptr;
  69.       char       *password;
  70.       int         c;
  71.       int         i;
  72.       int         fsent;
  73.       struct stat buf;
  74.  
  75.       long        current, last_start;
  76.  
  77.  
  78.       fsent = 0;
  79.  
  80.  
  81.       /*--------------------------------------------------------------------*/
  82.       /* Send all waiting ?UT files (mail bundles)                          */
  83.       /*--------------------------------------------------------------------*/
  84.       *ext_flags  = 'O';
  85.       for(c=0; c<NUM_FLAGS; c++)
  86.          begin
  87.             if (caller && (ext_flags[c] == 'H'))
  88.                continue;
  89.  
  90.             sprintf( fname,
  91.                      "%s%04x%04x.%cUT",
  92.                      ctl.hold_area,called_net,called_node,ext_flags[c]);
  93.             errno = 0;
  94.  
  95.             if (!stat(fname,&buf))
  96.                begin
  97.  
  98.                   /*--- Build a dummy PKT file name */
  99.                   invent_pkt_name(s);
  100.  
  101.                   /*--- Tell ZModem to handle this as a SEND AS then DELETE */
  102.                   status_line(BUNDLE_msg);
  103.  
  104.                   if (!(*wzsendfunc)(fname,s,DELETE_AFTER,fsent++,DO_WAZOO)) 
  105.                      begin
  106.                         net_problems   = 1;
  107.                         return FALSE;
  108.                      end
  109.  
  110. /*                  if ( (locate_y) and (locate_y!=0xffff) )
  111.                      gotoxy( 0, (byte )locate_y-1 );*/
  112.  
  113.                end
  114.  
  115.          end /* for */
  116.  
  117.  
  118.       /*--------------------------------------------------------------------*/
  119.       /* Send files listed in ?LO files (attached files)                    */
  120.       /*--------------------------------------------------------------------*/
  121.       *ext_flags  = 'F';
  122.       for(c=0; c<NUM_FLAGS; c++)
  123.          begin
  124.             if (caller && (ext_flags[c] == 'H'))
  125.                continue;
  126.  
  127.             sprintf( fname, "%s%04x%04x.%cLO",
  128.                      ctl.hold_area,called_net,called_node,ext_flags[c]);
  129.             errno = 0;
  130.  
  131.             if (!stat(fname,&buf))
  132.                begin
  133.  
  134.  
  135.                   errno = 0;
  136.                   fp = fopen( fname, rb_plus );
  137.                   if (got_error(OPEN_msg,fname))
  138.                      begin
  139.                         continue;
  140.                      end
  141.  
  142.                   current  = 0L;
  143.                   while(!feof(fp))
  144.                      begin
  145.                         s[0]        = 0;
  146.                         last_start  = current;
  147.                         fgets(s,79,fp);
  148.                         if (got_error(READ_msg,fname)) s[0] = 0;
  149.  
  150.                         sptr        = s;
  151.                         password    = NULL;
  152.  
  153.                         for(i=0; sptr[i]; i++)
  154.                            if (sptr[i]=='!') password = sptr+i+1;
  155.  
  156.                         if (password)
  157.                            begin
  158.                               password = sptr+i+1;
  159.                               for(i=0; password[i]; i++)
  160.                                  if (password[i]<=' ') password[i]=0;
  161.                               fancy_str(password);
  162.                               if (strcmp(password,remote_password))
  163.                                  begin
  164.                                     status_line("!RemotePwdErr %s %s",password,remote_password);
  165.                                     continue;
  166.                                  end
  167.                            end
  168.  
  169.                         for(i=0; sptr[i]; i++)
  170.                            if (sptr[i]<=' ') sptr[i]=0;
  171.  
  172.                         current     = ftell(fp);
  173.  
  174.                         if (sptr[0]=='#')
  175.                            begin
  176.                                sptr++;
  177.                               i     = TRUNC_AFTER;
  178.                            end
  179.                         else  i     = NOTHING_AFTER;
  180.  
  181.                         if (!sptr[0])
  182.                            begin
  183.                               continue;
  184.                            end
  185.  
  186.  
  187.                         if (sptr[0] != '~')
  188.                            begin
  189.  
  190.                               if (stat(sptr,&buf)) /* file exist? */
  191.                                  begin
  192.                                     got_error(FIND_msg,sptr);
  193.                                     continue;
  194.                                  end
  195.                               else if (!buf.st_size)
  196.                                  begin
  197.                                     continue; /* 0 length? */
  198.                                  end
  199.  
  200.                               if (!(*wzsendfunc)(sptr,NULL,i,fsent++,DO_WAZOO)) 
  201.                                  begin
  202.                                     fclose(fp);
  203.                                     net_problems   = 1;
  204.                                     return FALSE;
  205.                                  end
  206.  
  207.                               /*--------------------------------------------*/
  208.                               /* File was sent.  Flag file name             */
  209.                               /*--------------------------------------------*/
  210. /*                              if ( (locate_y) and (locate_y!=0xffff) )
  211.                                  gotoxy( 0, (byte )locate_y-1 );*/
  212.  
  213.                               fseek( fp, last_start, SEEK_SET );
  214.                               putc('~',fp); /* flag it */
  215.                               fflush (fp);
  216.                               rewind(fp); /* clear any eof flags */
  217.                               fseek( fp, current, SEEK_SET );
  218.                               errno = 0;
  219.  
  220.                            end
  221.  
  222.                      end /* while */
  223.  
  224.                   errno = 0;
  225.                   fclose(fp);
  226.                   got_error(CLOSE_msg,fname);
  227.                   unlink(fname);
  228.                   errno = 0;
  229.  
  230.                end /* !stat */
  231.  
  232.          end /* for */
  233.       
  234.       /*--------------------------------------------------------------------*/
  235.       /* Send our File requests to other system                             */
  236.       /*--------------------------------------------------------------------*/
  237.       sprintf( fname, request_template, ctl.hold_area, called_net, called_node );
  238.       if (!stat(fname,&buf))
  239.          begin
  240.  
  241.             if (!(remote_capabilities&WZ_FREQ)) status_line("*F.REQ. declined");
  242.             else
  243.                begin
  244.                   status_line("*Making file request");
  245.                   if ((*wzsendfunc)(fname,NULL,NOTHING_AFTER,fsent++,DO_WAZOO))
  246.                      unlink(fname);
  247.                end
  248.  
  249.          end
  250.  
  251.  
  252.  
  253.       fsent = respond_to_file_requests(fsent);
  254.  
  255.       errno = 0;
  256.       if (!fsent) status_line("+Nothing to send from %d/%d to %d/%d",
  257.                               ctl.alias[0].net, ctl.alias[0].node,
  258.                               called_net,       called_node );
  259.  
  260.       (*wzsendfunc)(NULL,NULL,NOTHING_AFTER,((fsent)?END_BATCH:NOTHING_TO_DO),DO_WAZOO);
  261.  
  262.       sent_mail = 1;
  263.  
  264.       return TRUE;
  265.  
  266.    end /* WaZOO */
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. /*--------------------------------------------------------------------------*/
  274. /* RESPOND TO FILE REQUEST                                                  */
  275. /*--------------------------------------------------------------------------*/
  276. int respond_to_file_requests(fsent)
  277.    int fsent;
  278.    begin
  279.  
  280.       static char  req[80];
  281.       extern char *n_frproc();
  282.       struct stat  buf;
  283.       FILE        *fp;
  284.       int          i;
  285.       int          np;
  286.       int          junk;
  287.       int          nfiles;
  288.       byte        *rqname;
  289.  
  290.  
  291.       if (!(ctl.matrix_mask&TAKE_REQ)) goto done;
  292.  
  293.       for (np = 0; np <= 10; np++)
  294.          begin
  295.             if (ctl.alias[np].net == 0)
  296.                break;
  297.  
  298.             sprintf(req,request_template,ctl.filepath,
  299.                     ctl.alias[np].net,ctl.alias[np].node);
  300.  
  301.             if (!stat(req,&buf))
  302.                begin
  303.                   errno = 0;
  304.                   fp = fopen(req,read_ascii);
  305.                   if (got_error(OPEN_msg,req)) goto done;
  306.                   nfiles = 0;
  307.                   while(!feof(fp))
  308.                      begin
  309.                         req[0] = 0;
  310.                         if (fgets(req,79,fp) == NULL)
  311.                            break;
  312.  
  313.                         /* ; as the first char is a comment */
  314.                         if (req[0] == ';')
  315.                            continue;
  316.  
  317.                         junk = -1;
  318.                         do
  319.                            begin
  320.                               if ((rqname = n_frproc(req, &junk, 0)) != NULL)
  321.                                  if (!(*wzsendfunc)(rqname,NULL,NOTHING_AFTER,fsent++,DO_WAZOO))
  322.                                     goto done;
  323.                               ++nfiles;
  324.                               if (nfiles > n_requests)
  325.                                  begin
  326.                                     status_line ("!File Request limit exceeded");
  327.                                     junk = -1;
  328.                                  end
  329.                            end
  330.                         while (CARRIER && (junk >= 0));
  331.                      end
  332.  
  333.                   sprintf(req,request_template,ctl.filepath,
  334.                           ctl.alias[np].net,ctl.alias[np].node);
  335.                   errno = 0;
  336.                   fclose(fp);
  337.                   got_error(CLOSE_msg,req);
  338.  
  339.                   /* Note that Opus does not delete this file, but we should I think */
  340.                   unlink(req);
  341.                   got_error(UNLINK_msg,req);
  342.                   /* once we have satisfied a request, we can get out of here */
  343.                   break;
  344.                end
  345.          end
  346.  
  347. done:
  348.       return fsent;
  349.  
  350.    end
  351.